package com.ruoyi.framework.shiro.subject;

import com.ruoyi.framework.shiro.auth.CustomizedToken;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.subject.Subject;
import org.apache.shiro.subject.SubjectContext;
import org.apache.shiro.web.mgt.DefaultWebSubjectFactory;

public class Pac4jSubjectFactory extends DefaultWebSubjectFactory {

    @Override
    public Subject createSubject(final SubjectContext context) {

        boolean authenticated = context.isAuthenticated();

        if (authenticated) {
            AuthenticationToken token = context.getAuthenticationToken();

            if (token != null && token instanceof CustomizedToken) {
                final CustomizedToken clientToken = (CustomizedToken) token;
                if (clientToken.isRememberMe()) {
                    context.setAuthenticated(false);
                }
            }
        }

        context.setSessionCreationEnabled(true);
        return super.createSubject(context);
    }
}
